#include "CapturExports.h"
#include "ReceiveAndPlay.h"
#include "CaptrueToFile.h"
#include "CaptureAndSend.h"
#include "common.h"
#include "DeviceCaptureAndSend.h"

ReceiveAndPlay* CreateReceiveAndPlay(bool isTrans, bool isBroadcastReceive)
{
	ReceiveAndPlay* receiveAndPlay = NULL;
	try{
		receiveAndPlay = new ReceiveAndPlay(isTrans, isBroadcastReceive);
	}catch(...)
	{
		ErrorPrint("Create receive and play error");
		receiveAndPlay = NULL;
	}
	return receiveAndPlay;
}

bool ReceiveAndPlayStart(ReceiveAndPlay* receiveAndPlay)
{
	return receiveAndPlay->start();
}

bool ReceiveAndPlaySetSocket(ReceiveAndPlay* receiveAndPlay, SOCKET sockFd)
{
	return receiveAndPlay->setSocket(sockFd);
}

bool ReceiveAndPlaySetVideoSocket(ReceiveAndPlay* receiveAndPlay, SOCKET sockFd)
{
	return receiveAndPlay->setVideoSocket(sockFd);
}

bool ReceiveAndPlayCloseVideoSocket(ReceiveAndPlay* receiveAndPlay)
{
	return receiveAndPlay->closeVideoSocket();
}

bool ReceiveAndPlaySetAudioSocket(ReceiveAndPlay* receiveAndPlay, SOCKET sockFd)
{
	return receiveAndPlay->setAudioSocket(sockFd);
}

bool ReceiveAndPlayCloseAudioSocket(ReceiveAndPlay* receiveAndPlay)
{
	return receiveAndPlay->closeAudioSocket();
}

bool ReceiveAndPlayAddTransVideoSocket(ReceiveAndPlay* receiveAndPlay, SOCKET sockFd)
{
	return receiveAndPlay->addTransVideoSocket(sockFd);
}

bool ReceiveAndPlayRemoveAllTransVideoSocket(ReceiveAndPlay* receiveAndPlay)
{
	return receiveAndPlay->removeAllTransVideoSocket();
}

bool ReceiveAndPlayRemoveAllTransAudioSocket(ReceiveAndPlay* receiveAndPlay)
{
	return receiveAndPlay->removeAllTransAudioSocket();
}

bool ReceiveAndPlayAddTransAudioSocket(ReceiveAndPlay* receiveAndPlay, SOCKET sockFd)
{
	return receiveAndPlay->addTransAudioSocket(sockFd);
}

bool ReceiveAndPlayStop(ReceiveAndPlay* receiveAndPlay)
{
	return receiveAndPlay->stop();
}

bool ReceiveAndPlaySetFullScreen(ReceiveAndPlay* receiveAndPlay, bool isFull)
{
	return receiveAndPlay->setFullScreen(isFull);
}

bool ReceiveAndPlaySetParentWindow(ReceiveAndPlay* receiveAndPlay, HANDLE parent)
{
	return receiveAndPlay->setParentWindow(parent);
}

void ReceiveAndPlaySetVisual(ReceiveAndPlay* receiveAndPlay,bool visual /* = true */)
{
	receiveAndPlay->setVisual(visual);
}

void ReceiveAndPlaySetVolume(ReceiveAndPlay* receiveAndPlay, float volume)
{
	receiveAndPlay->setVolume(volume);
}

void ReceiveAndPlaySetPlayMode(ReceiveAndPlay* receiveAndPlay, int mode)
{
	receiveAndPlay->setPlayMode(mode);
}


CaptureToFile* CreateCaptureToFile()
{
	CaptureToFile* captureToFile = NULL;
	try{
		captureToFile = CaptureToFile::instance();
	}catch(...)
	{
		ErrorPrint("Create capture to file error");
		captureToFile = NULL;
	}
	return captureToFile;
}

bool CaptureToFileStart(CaptureToFile* captrueToFile, const wchar_t* fileName)
{
	return captrueToFile->start(fileName);
}

bool CaptureToFileStop(CaptureToFile* captrueToFile)
{
	return captrueToFile->stop();
}



CaptureAndSend* CreateCaptureAndSend()
{
	CaptureAndSend* captureAndSend = NULL;
	try{
		captureAndSend = CaptureAndSend::instance();
	}catch(...)
	{
		ErrorPrint("Create capture and send error");
		captureAndSend = NULL;
	}
	return captureAndSend;
}

bool CaptureAndSendStart(CaptureAndSend* captureAndSend)
{
	return captureAndSend->start();
}

bool CaptureAndSendStop(CaptureAndSend* captureAndSend)
{
	return captureAndSend->stop();
}

bool CaptureAndSendPause(CaptureAndSend* captureAndSend)
{
	return captureAndSend->pause();
}

bool CaptureAndSendSetSocket(CaptureAndSend* captureAndSend, SOCKET sockFd)
{
	return captureAndSend->setSocket(sockFd);
}

DeviceCaptureAndSend* CreateDeviceCaptureAndSend(const wchar_t* captureDeviceFriendlyName)
{
	DeviceCaptureAndSend* object = NULL;
	try{
		object = new DeviceCaptureAndSend(captureDeviceFriendlyName);
	}catch(...)
	{
		return NULL;
	}
	return object;
}

bool DeviceCaptureAndSendStart(DeviceCaptureAndSend* object)
{
	return object->start();
}

bool DeviceCaptureAndSendPause(DeviceCaptureAndSend* object)
{
	return object->pause();
}


bool DeviceCaptureAndSendStop(DeviceCaptureAndSend* object)
{
	return object->stop();
}

bool DeviceCaptureAndSendAddVideoSocket(DeviceCaptureAndSend* object, SOCKET sockFd)
{
	return object->addVideoSocket(sockFd);
}

bool DeviceCaptureAndSendAddAudioSocket(DeviceCaptureAndSend* object, SOCKET sockFd)
{
	return object->addAudioSocket(sockFd);
}

bool DeviceCaptureAndSendClearAllSocket(DeviceCaptureAndSend* object)
{
	return object->clearAllSocket();
}

bool DeviceCaptureAndSendDelete(DeviceCaptureAndSend* object)
{
	delete object;
	return true;
}

bool DeviceCaptureAndSendGetPreviewSize(DeviceCaptureAndSend* object, long* width, long* height)
{
	return object->getPreviewWindowSize(width, height);
}

bool DeviceCaptureAndSendSetPreivewParent(DeviceCaptureAndSend* object, HANDLE parent)
{
	return object->setPreviewParent(parent);
}

bool DeviceCaptureAndSendResetDevice(DeviceCaptureAndSend* object, const wchar_t* deviceName)
{
	return object->resetDevice(deviceName);
}

bool DeviceCaptureAndSendGetInputVideoPinNames(DeviceCaptureAndSend* object, wchar_t** videoInputPinNameList, int* count, int maxSize)
{
	std::vector<std::wstring> nameList;
	if (!object->getVideoInputPinNames(nameList))
	{
		return false;
	}
	for (size_t i = 0; i < nameList.size() && i < *count; ++i)
	{
		wcscpy_s(videoInputPinNameList[i], maxSize ,nameList[i].c_str());
	}
	*count = nameList.size();
	return true;
}

bool DeviceCaptureAndSendSetVideoInputPin(DeviceCaptureAndSend* object, int inputPinIndex)
{
	return object->setVideoInputPin(inputPinIndex);
}

bool GetVideoCaptureDeviceNames(wchar_t** captureDeviceNameList, int* count,int maxSize)
{
	std::vector<IBaseFilter*> filterList;
	std::vector<std::wstring> nameList;
	if (!GetVideoCaptureDevices(filterList, nameList))
	{
		return false;
	}
	for (size_t i = 0; i < nameList.size() && i < *count ; ++i) 
	{
		wcscpy_s(*(captureDeviceNameList+i), maxSize, nameList[i].c_str());
	}
	*count = nameList.size();
	return true;
}